class SearchController < ApplicationController
  def index
    @photos = Photo.search("#{[params[:term]]}")
    @videos = Video.search("#{[params[:term]]}")
    @comments = Comment.search("#{[params[:term]]}")
    @galleries = Gallery.search("#{[params[:term]]}")
    @pages = Page.search("#{[params[:term]]}")
    unless logged_in? && current_user.is_admin?
      @photos.reject!     {|photo|    photo.is_private?   || photo.is_invisible?}
      @videos.reject!     {|video|    video.is_private?   || video.is_invisible?}
      @comments.reject!   {|comment|  comment.is_private? || comment.is_invisible?}
      @galleries.reject!  {|gallery|  gallery.private?    || gallery.invisible?}
      @pages.reject!      {|page|     page.private?       || page.invisible?}
    end
  end
  
  def gallery_photo_search
    @gallery = Gallery.find(params[:gallery_id], :include => :photos)
    @photos = Photo.search("#{[params[:term]]}")
    render :partial => "gallery_edit_photos"
  end
  
  def galleries
    @galleries = Gallery.search "#{[params[:term]]}", :order => "created_at desc"
    unless logged_in? && current_user.is_admin?
      @galleries.reject! {|gallery| gallery.private? || gallery.invisible?}
    end
  end
end
